
public class CheckAndUpdatePlayerBuildings {

	private int size, numHouses, numHotels;
	private String name, dir;
	
	public CheckAndUpdatePlayerBuildings(Player p, LayeredGameBoardPanel lgbp)
	{
		dir = "south";
		size = p.getDarkPurpleSize();
		for(int i = 0; i < size; i++)
		{
			name = p.getDarkPurpleNameAt(i);
			
			if(p.hasHotel(name) == false)
			{
				numHouses = p.getNumberOfHouses(p.getDarkPurpleNameAt(i));
				lgbp.buildHouses(numHouses, dir, name);
			}
			else if(p.hasHotel(name) == true)
			{
				lgbp.removeAllHouses(dir, name);
				lgbp.buildHotel(dir, name);
			}
		}
		
		size = p.getLightBlueSize();
		for(int i = 0; i < size; i++)
		{
			name = p.getLightBlueNameAt(i);

			if(p.hasHotel(name) == false)
			{
				numHouses = p.getNumberOfHouses(p.getLightBlueNameAt(i));			
				lgbp.buildHouses(numHouses, dir, name);
			}
			else if(p.hasHotel(name) == true)
			{
				lgbp.removeAllHouses(dir, name);
				lgbp.buildHotel(dir, name);
			}
		}
		
		dir = "west";
		size = p.getLightPurpleSize();
		for(int i = 0; i < size; i++)
		{
			name = p.getLightPurpleNameAt(i);
			
			if(p.hasHotel(name) == false)
			{
				numHouses = p.getNumberOfHouses(p.getLightPurpleNameAt(i));
				lgbp.buildHouses(numHouses, dir, name);
			}
			else if(p.hasHotel(name) == true)
			{
				lgbp.removeAllHouses(dir, name);
				lgbp.buildHotel(dir, name);
			}
		}		

		size = p.getOrangeSize();
		for(int i = 0; i < size; i++)
		{
			name = p.getOrangeNameAt(i);
			
			if(p.hasHotel(name) == false)
			{
				numHouses = p.getNumberOfHouses(p.getOrangeNameAt(i));			
				lgbp.buildHouses(numHouses, dir, name);
			}
			else if(p.hasHotel(name) == true)
			{
				lgbp.removeAllHouses(dir, name);
				lgbp.buildHotel(dir, name);
			}
		}

		dir = "north";
		size = p.getRedSize();
		for(int i = 0; i < size; i++)
		{
			name = p.getRedNameAt(i);
			
			if(p.hasHotel(name) == false)
			{
				numHouses = p.getNumberOfHouses(p.getRedNameAt(i));			
				lgbp.buildHouses(numHouses, dir, name);
			}
			else if(p.hasHotel(name) == true)
			{
				lgbp.removeAllHouses(dir, name);
				lgbp.buildHotel(dir, name);
			}
		}

		size = p.getYellowSize();
		for(int i = 0; i < size; i++)
		{
			name = p.getYellowNameAt(i);
			
			if(p.hasHotel(name) == false)
			{
				numHouses = p.getNumberOfHouses(p.getYellowNameAt(i));			
				lgbp.buildHouses(numHouses, dir, name);
			}
			else if(p.hasHotel(name) == true)
			{
				lgbp.removeAllHouses(dir, name);
				lgbp.buildHotel(dir, name);
			}
		}
		
		dir = "east";
		size = p.getGreenSize();
		for(int i = 0; i < size; i++)
		{
			name = p.getGreenNameAt(i);
			
			if(p.hasHotel(name) == false)
			{
				numHouses = p.getNumberOfHouses(p.getGreenNameAt(i));			
				lgbp.buildHouses(numHouses, dir, name);
			}
			else if(p.hasHotel(name) == true)
			{
				lgbp.removeAllHouses(dir, name);
				lgbp.buildHotel(dir, name);
			}
		}
		
		size = p.getDarkBlueSize();
		for(int i = 0; i < size; i++)
		{
			name = p.getDarkBlueNameAt(i);
			
			if(p.hasHotel(name) == false)
			{
				numHouses = p.getNumberOfHouses(p.getDarkBlueNameAt(i));			
				lgbp.buildHouses(numHouses, dir, name);
			}
			else if(p.hasHotel(name) == true)
			{
				lgbp.removeAllHouses(dir, name);
				lgbp.buildHotel(dir, name);
			}
		}
	}
}
